package com.tianqu.tms.www.statistics.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsStatisticsAjaxAction;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.www.api.form.OutputParam;
import com.tianqu.tms.www.api.form.ResultModel;
import com.tianqu.tms.www.api.network.PSHTTPUtil;
import com.tianqu.tms.www.statistics.dto.BusinessTransactionDto;
import com.tianqu.tms.www.statistics.service.BusinessTransactionService;
/**
 * 商户交易
 * @author shaoyu
 *
 */
public class BusinessTransactionController extends TmsStatisticsAjaxAction {

	private Logger LOGGER = Logger.getLogger(BusinessTransactionController.class);
	private BusinessTransactionService businessTransactionService = new BusinessTransactionService();

	/**
	 * 实时统计/月销售量（量）/月收车量（万元）
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward businessTransaction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws TmsException {

		String json = "";
		ResultModel<OutputParam> rop = new ResultModel<OutputParam>(); 
		OutputParam responseObj = new OutputParam();
		try {
			BusinessTransactionDto businessTransactionDto = businessTransactionService.getBusinessTransactionCount();
			json = PSHTTPUtil.convertJavaBeanToJson(businessTransactionDto);
//			rop.setResultCode(GateResult.SUCCESS.getValue());
//			rop.setResultData(responseObj);
		} catch (Exception e) {
			LOGGER.error("tmsCarGateAction web api error",e);
//			rop.setResultCode(GateResult.RESULT_06.getValue());
		}
		LOGGER.debug("call car gateway:param:"+json +"   result:"+json);
		responseValues(response, json, JSON);
		
		return null;
	}
	
	/**
	 * 当月月销售量（量）同比、环比/月收车量（万元）同比、环比
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward businessTransactionMonth(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws TmsException {

		String json = "";
		ResultModel<OutputParam> rop = new ResultModel<OutputParam>(); 
		OutputParam responseObj = new OutputParam();
		try {
			BusinessTransactionDto businessTransactionDto = businessTransactionService.getVolumeAndRatio();
			json = PSHTTPUtil.convertJavaBeanToJson(businessTransactionDto);
		} catch (Exception e) {
			LOGGER.error("tmsCarGateAction web api error",e);
		}
		LOGGER.debug("call car gateway:param:"+json +"   result:"+json);
		responseValues(response, json, JSON);
		
		return null;
	}
}
